JSC : A JavaScript Object System

نویسنده

  • Artur Ventura
چکیده

The JSC language is a superset of JavaScript designed to ease the development of large web applications. This language extends JavaScript’s own object system by isolating code in a class declaration, simplifying multiple inheritance and using method implementation agreements. 1 Motivation As web applications have been gaining more dynamic behavior, JavaScript has become more important in web development. As such, it is useful to use a software engineering aproach to JavaScript. JavaScript object-oriented model is prototype-based. This model can be extremely versatile to develop. However, in a large team of developers, not only problems such as name colisions and unintentional method redefinition can occur, but also maintenance becomes an issue. JSC attempts to remedy some of these issues by implementing a Object System on top of standard JavaScript. 2 Related Work There have been some attemps to add structed programming to Javascript. In ECMAScript (language from witch JavaScript is a dialect) last version were added support for defining classes. Another dialect of ECMAScript, ActionScript supports defining classes. Althought those systems are more advanced (they support typechecking via anotation on variables, generics, dynamic classes, templates, etc.), they aren’t avaible in the current browsers. It’s expected that future versions of JavaScript extends this behavior from ECMAScript. Other attempt have been creating creating supersets to JavaScript. One example of this is Objective-J. This is a sctrict superspet of Javascript, but adds a object system by implementing a language similar to Objective-C. This aproach is similar to JSC, but this language uses the same message passing than Objective-C making the methods unparsable by JavaScript. 1 ar X iv :0 91 2. 28 61 v1 [ cs .P L ] 1 5 D ec 2 00 9 3 Object Oriented JavaScript In JavaScript, a class is a function, so its definition is similar to the definition of a function, as shown next: 1 function Rectangle(w, h) { 2 this.width = w; 3 this.height = h; 4 } A function in javascript is of type Function but behaves similarly to a hash or a dictionary. One of the properties in this object is the prototype. This property represents a structure that is not yet fully defined and it is only formed when it is instantiated. Instantiation can be done by: new Rectangle(10,10); new operator will invoke the function Rectangle with this as a new object with a reference to Rectangle.prototype, and return this object.Any changes made to this object will only afect the new object, and not the prototype. If a property is not defined in the object but on the prototype, then the prototype’s value is returned. A method can be defined by adding a function to the class prototype as shown next: 1 Rectangle.prototype.getArea = function (){ 2 return this.height * this.width; 3 } Methods are called like this: rectangle.getHeight() As with the constructor, getHeight will be invoked with this as a reference to the instance, in this case to rectangle. This method will be avaible to all instances that don’t define localy the method getArea. The code below shows how inheritance is implemented: by copying the prototype of the superclass to the subclass. 1 function PositionedRectangle(x, y, w, h) { 2 Rectangle.call(this, w, h); 3 4 this.x = x; 5 this.y = y; 6 } 7 PositionedRectangle.prototype = new Rectangle(); 1Actually Rectangle could return anything, but the default is this

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

JavaScript: Bringing Object-Level Security to the Browser

JavaScript has evolved from a simple language intended to give web browsers basic interaction into a fully featured dynamic language that allows the browser to become an application delivery platform. With innovations such as asynchronous JavaScript and XML (AJAX) and JavaScript Object Notation (JSON), JavaScript has become the de facto standard for creating interactive web applications. With i...

متن کامل

Type Checking for JavaScript

JavaScript is a powerful imperative object based language made popular by its use in web pages. It supports flexible program development by allowing dynamic addition of members to objects. Code is dynamically typed: a runtime access to a non-existing member causes an error. We suggest two static type systems for JavaScript that will detect such runtime type errors. Therefore, programmers can ha...

متن کامل

SJS: A Type System for JavaScript with Fixed Object Layout

We propose a static type system for a significant subset of JavaScript, dubbed SJS, with the goal of ensuring that objects have a statically known layout at the allocation time, which in turn can enable an ahead-of-time (AOT) compiler to generate efficient code. The main technical challenge we address is to ensure fixed object layout, while supporting popular language features such as objects w...

متن کامل

A Survey of Object Oriented JavaScript Language

Many of the programmers move towards object oriented programming languages due to its reusability nature, whereas in procedural programming languages reusability is not allowed, which may contribute to the high cost of development. Most of web browsers make use of JavaScript as a user interactive program that is a client side program due to its active nature. In the client side programming it i...

متن کامل

Towards a Type System for Analyzing JavaScript Programs

JavaScript is a popular language for client-side web scripting. It has a dubious reputation among programmers for two reasons. First, many JavaScript programs are written against a rapidly evolving API whose implementations are sometimes contradictory and idiosyncratic. Second, the language is only weakly typed and comes virtually without development tools. The present work is a first attempt t...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:
  • CoRR

دوره abs/0912.2861  شماره 

صفحات  -

تاریخ انتشار 2009